<template>
	<view>
		<view class="userinfo">
			<u-avatar @click="personal" class="avatar" :size="100" :src="userInfo.avatar"></u-avatar>

			<view class="flex" style="align-items: flex-end;justify-content: space-between;">

				<view class="text_2" @click="personal">

					<text v-if="!userInfo.id">
						{{$t('请先登录') }}
					</text>
					<text v-else>
						<view
							style="width: 400rpx; word-break: break-all;overflow: hidden;display: -webkit-box;-webkit-line-clamp: 1;-webkit-box-orient: vertical;">
							{{ userInfo[$t('item.user.username')]||$t('立即认证')}}
						</view>
					</text>
				</view>

				<view class="flex" v-if="userStatus>0&&userInfo.label.length>0">
					<block v-if="userInfo&&userInfo.label&&userInfo.label.length!=0">
						<block v-for="(item,index) in [userInfo.label[0]]" :key="index" v-if="item.id==11||item.id==12">
							<u-image class="ui-image" height="30rpx" width="40rpx" :src="ImageUrl(item.url)">
							</u-image>
							<view class="role-name">
								{{ userInfo[$t('item.user.identity_name')] }}
							</view>
							<image class="ui-image" @click="personal" :src='serverImageUrl("/static/images/edit.png")'
								style="width: 30rpx;  height: 30rpx;"></image>
						</block>
					</block>

					<block v-else>
						<view style="width: 68%;"></view>
						<image class="ui-image" @click="personal" :src='serverImageUrl("/static/images/edit.png")'
							style="width: 35rpx; margin-top: 5rpx; height: 35rpx;"></image>
					</block>

				</view>
			</view>
			<view class="desc" v-if="userInfo.profile">
				{{$t("简介")}}：
				<text v-if="lang=='zh'">{{userInfo.profile||'没有简介'}}</text>
				<text v-else>{{userInfo.profile_ru||'Введение еще не заполнено'}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		createC2CConversation,
		ImageUrl
	} from "@/common/public";
	export default {
		props: ["userInfo", "userStatus", "userInfoFull"],
		data() {
			return {
				lang: getApp().globalData.lang,
				model: {
					username: '', //公司名称
					truename: '', //联系人（真实姓名）
					mobile: '', //联系电话
					idnum: '', //身份证号码
					area_id: [], //所在区域
					reg_address: '', //详细地址
					email: '', //邮箱
					fax: '', //传真
					weblink: '', //网站
					provide_transport: [], //运输工具
					transport_list: [{
						departureCity: '',
						arrivingCity: '',
						departureid: '',
						arrivingid: '',
						days: 0
					}], //运输路线
					main_product: '', //公司介绍
					product_image: [], //企业logo
					license_image: [], //营业执照 （资质证明）
					buy_videos: [], //企业宣传视频
					shop_image: [], //企业宣传图
					id: ''
				}
			}
		},
		mounted() {
			console.log(this.userInfoFull.user_id)
			this.getData(this.userInfoFull.user_id)
		},
		methods: {
			ImageUrl,
			//个人资料跳转
			personal() {
				var that = this
				this.$u.api.user.is_user().then(r => {
					if (r) {
						//判断当前用户角色 决定跳转位置
						const identity_type = uni.getStorageSync("identity_type")
						let url = "pages/user/personal/personal"
						if ([2, 5, 6, 7].indexOf(Number(identity_type)) > -1) url =
							"pages/tabbar/order/card/cardIndex"
						that.$u.route({
							url,
							// url: 'pages/tabbar/order/ImproveInformation',
							params: {
								// id: this.userInfo.user_id
								// model: JSON.stringify(this.model)
							}
						})
					} else {
						that.$u.toast(that.$t('请先登录'));
						setTimeout(() => {
							// 此为uView的方法，详见路由相关文档
							that.$u.route('/pages/user/login/login')
						}, 1000)
					}
				})
			},
			getData(id) {
				let data = {
					user_id: id,
					type: 1,
					from: ''
				}
				this.$u.api.user.getUserHomepage(data).then(res => {
					let ared = []
					ared.push({
						label: this.lang == 'zh' ? res.userInfo.area_id.country_name : res.userInfo.area_id
							.country_name_ru,
						value: res.userInfo.area_id.country
					})
					ared.push({
						label: this.lang == 'zh' ? res.userInfo.area_id.province_name : res.userInfo
							.area_id.province_name_ru,
						value: res.userInfo.area_id.province
					})
					ared.push({
						label: this.lang == 'zh' ? res.userInfo.area_id.city_name : res.userInfo.area_id
							.city_name_ru,
						value: res.userInfo.area_id.city
					})
					let datas = {
						// country_name:res.userInfo.label[0].id,
						username: this.lang == 'zh' ? res.userInfo.username : res.userInfo.username_ru, //公司名称
						truename: this.lang == 'zh' ? res.userInfo.truename : res.userInfo
							.truename_ru, //联系人（真实姓名）
						mobile: res.userInfo.mobile, //联系电话
						idnum: res.userInfo.id_card, //身份证号码
						// label value
						area_id: ared, //所在区域
						reg_address: res.userInfo.reg_address, //详细地址
						email: res.userInfo.email, //邮箱
						fax: res.userInfo.fax, //传真
						weblink: res.userInfo.weblink, //网站
						// children id name user path
						provide_transport: res.userInfo.provide_transport.split(','), //运输工具
						transport_list: res.luxian.map(item => {
							return {
								departureCity: this.lang == 'zh' ? item.cfd.shortname : item.cfd
									.shortname_ru,
								arrivingCity: this.lang == 'zh' ? item.mdd.shortname : item.mdd
									.shortname_ru,
								departureid: item.cfd.id,
								arrivingid: item.mdd.id,
								days: 0
							}
						}),
						main_product: this.lang == 'zh' ? res.userInfo.main_product : res.userInfo
							.main_product_ru, //公司介绍
						product_image: res.userInfo.product_image, //企业logo
						license_image: res.userInfo.license_image2, //营业执照 （资质证明）

						buy_videos: [res.userInfo.buy_videos], //企业宣传视频
						shop_image: res.userInfo.shop_image, //企业宣传图
					}
					this.model = datas
					console.log('完善信息:', this.model);
				})
			},
		}
	}
</script>

<style lang="scss">
	.userinfo {
		margin-top: 50rpx;
		margin-bottom: 40rpx;
	}

	.avatar {
		margin-bottom: 24rpx;
	}

	.text_2 {
		font-size: 40rpx;
		font-weight: 600;
		margin-right: 18rpx;
		max-width: 500rpx;
	}

	.flex {
		display: flex;
		align-items: center;
	}

	.desc {
		margin-top: 24rpx;
		color: #999;
		font-size: 24rpx;
		height: 24rpx;
		line-height: 24rpx;
		width: 100%;
		white-space: nowrap;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	.role-name {
		margin-left: 8rpx;
		margin-right: 8rpx;
		color: #666;
	}
</style>